<template>
	<view class="detail">
		<view class="title">
			{{detail.title}}
			<view class="info">
				<view class="author">
					编辑:{{detail.author}}
				</view>
				<view class="time">
					发布日期:{{detail.posttime}}
				</view>
			</view>
			<view class="content">
				<rich-text :nodes="detail.content"></rich-text>
			</view>
			<view class="description">
				与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关与我无关
			</view>
		</view>
	</view>
</template>

<script>
	import {
		parseTime,
		arrToHeavy
	} from '@/utils/tool.js'
	import {
		parse
	} from 'url';

	export default {
		data() {
			return {
				options: null,
				detail: {}
			};
		},
		onLoad(e) {
			this.options = e
			this.getDetail()

		},
		methods: {
			getDetail() {
				uni.request({
					url: "https://ku.qingnian8.com/dataApi/news/detail.php",
					data: this.options,
					success: res => {
						// console.log(res.data)
						res.data.posttime = parseTime(res.data.posttime)
						res.data.content = res.data.content.replace(/<img/gi, '<img style="max-width:100%"')
						this.detail = res.data
						this.saveHistory() // 缓存
						uni.setNavigationBarTitle({
							title: this.detail.title
						})
					}
				})
			},
			saveHistory() {
				let historyArr = uni.getStorageSync("historyArr") || []
				let item = {
					id: this.detail.id,
					classid: this.detail.classid,
					picurl: this.detail.picurl,
					title: this.detail.title,
					looktime: parseTime(Date.now())
				}
				historyArr.unshift(item)
				// 数组对象去重
				historyArr =  arrToHeavy(historyArr)
				historyArr = historyArr.slice(0,10)
				uni.setStorageSync("historyArr", historyArr)

			}

			//	
		}
	}
</script>

<style lang="scss">
	.detail {
		padding: 30rpx;

		.title {
			font-size: 46rpx;
			color: #333;
		}

		.info {
			background: #F6F6F6;
			padding: 20rpx 10rpx;
			font-size: 25rpx;
			color: #666;
			display: flex;
			justify-content: space-between;
			margin: 40rpx 0;
		}

		.content {
			padding-bottom: 50rpx;

		}

		.description {
			background: #FEF0F0;
			font-size: 26rpx;
			padding: 20rpx;
			line-height: 1.8em;
		}
	}
</style>